package user

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	rpc "gitee.com/liuxuezhan/ar-platform/rpc-client/userServiceClient/userrpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpdateCurrencyExpRateConfigLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserUpdateCurrencyExpRateConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpdateCurrencyExpRateConfigLogic {
	return &UserUpdateCurrencyExpRateConfigLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserUpdateCurrencyExpRateConfigLogic) UserUpdateCurrencyExpRateConfig(req *types.CurrencyExpExchangeConfigUpdateRequest) (resp *types.CurrencyExpExchangeConfigUpdateResponse, err error) {
	rpcReq := &rpc.UpdateServiceConfigRequest{
		Id:          req.ConfigId,
		ConfigValue: req.ExchangeRate,
	}
	_, err = l.svcCtx.UserServiceRPC.UserUpdateServiceConfig(l.ctx, rpcReq)
	if err != nil {
		return nil, err
	}
	resp = &types.CurrencyExpExchangeConfigUpdateResponse{}
	return
}
